/**
 * 
 */
package es.aradesh.ministryassist.logic.ministry;

import java.sql.Date;

import es.aradesh.ministryassist.db.DbAdapter;
import es.aradesh.ministryassist.db.NoteColumns;

/**
 * @author xmorales
 * 
 */
public class Note implements MinistryElement{
	public static enum TYPE {
		// This enum must coincide with the order of array note_type
		NOTA,
		LIBRO,
		ATALAYA,
		DESPERTAD,
		ATA_Y_DESP,
		FOLLETO
	};
	//public static final int TYPE_APPEND = 0;
	//public static final int TYPE_PUBLICATION = 1;
	

	private long id;
	private String text;
	private Home home;
	private int type;
	private Date creationDate;

	/**
	 * @param id
	 * @param text
	 * @param home
	 * @param type
	 * @param creationdate
	 * @param modificationDate
	 */
	public Note(long id, String text, Home home, int type, Date creationdate) {
		this.id = id;
		this.text = text;
		this.home = home;
		this.type = type;
		this.creationDate = creationdate;
	}

	/**
	 * @return the name
	 */
	public String getText() {
		return text;
	}

	/**
	 * @return the home
	 */
	public Home getHome() {
		return home;
	}

	/**
	 * @return the type
	 */
	public int getType() {
		return type;
	}

	/**
	 * @return the date of creation
	 */
	public Date getCreationDate() {
		return creationDate;
	}

	/**
	 * @return the id
	 */
	public long getId() {
		return id;
	}

	/**
	 * @param id
	 *            the id to set
	 */
	public void setId(long id) {
		this.id = id;
	}

	/**
	 * @param name
	 *            the name to set
	 */
	public void setText(String text) {
		this.text = text;
	}

	/**
	 * @param home
	 *            the home to set
	 */
	public void setHome(Home home) {
		this.home = home;
	}

	/**
	 * @param type
	 *            the type to set
	 */
	public void setType(int type) {
		this.type = type;
	}

	/**
	 * @param date
	 *            the date of creation to set
	 */
	public void setCreationDate(Date date) {
		this.creationDate = date;
	}

	/* (non-Javadoc)
	 * @see es.aradesh.ministryassist.logic.ministry.MinistryElement#refreshDB(es.aradesh.ministryassist.DbAdapter)
	 */
	public void refreshDB(DbAdapter db) {
		// TODO Auto-generated method stub
		
	}

	public String toString() {
		String date = this.creationDate.toLocaleString();
		String type = "";
		if (this.type!=0) type = TYPE.values()[this.type] +" ";
		return date.split(" ")[0] + " " + type + this.text;
	}

	/* (non-Javadoc)
	 * @see es.aradesh.ministryassist.logic.ministry.MinistryElement#getActivityEditType()
	 */
	public int getActivityEditType() {
		// TODO Auto-generated method stub
		return -1;
	}

	public boolean delete(DbAdapter db) {
		return db.removeById(DbAdapter.TABLE_NOTES, this.id);
	}

	/* (non-Javadoc)
	 * @see es.aradesh.ministryassist.logic.ministry.MinistryElement#getParam(java.lang.String)
	 */
	public Object getParam(String parameter) {
		Object result = null;
		if(parameter == NoteColumns.DESCRIPTION) result = this.text;
		else if(parameter == NoteColumns.CREATIONDATE) result = this.creationDate;
		else if(parameter == NoteColumns.TYPE) result = this.type;
		return result;
	}
}
